//
//  OrderDetailHeaderView.m
//  BigJoy
//
//  Created by Rowling on 2017/7/11.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "OrderDetailHeaderView.h"
#import "SingleView.h"
#import "SingleImageCell.h"

@interface OrderDetailHeaderView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (nonatomic,strong) UICollectionView *collectionView;

@end

@implementation OrderDetailHeaderView

+(instancetype)fastLogin{
    return FastLogin;
}

-(UICollectionView *)collectionView {
    if (_collectionView == nil) {
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
        layout.itemSize = CGSizeMake(85, 85);
        layout.minimumInteritemSpacing = 15;
        layout.sectionInset = UIEdgeInsetsMake(0, 15, 10, 15);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([SingleImageCell class]) bundle:nil] forCellWithReuseIdentifier:@"Cell"];
    }
    return _collectionView;
}

-(void)setCount:(NSInteger)count {
    _count = count;
    if (count == 1) {
        SingleView * singleView = [SingleView fastLogin];
        [self.contentView addSubview:singleView];
        [singleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.right.equalTo(self.contentView);
        }];
    } else if (count > 1) {
        [self layoutIfNeeded];
        [self.contentView addSubview:self.collectionView];
    }
}

-(void)layoutSubviews {
    if (self.count > 1) {
        self.collectionView.frame = self.contentView.bounds;
    }
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SingleImageCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    return cell;
}

@end
